var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var db = require('./model/db.js');
var cookieParser = require('cookie-parser')
var session=require('express-session')

//这些设定好之后post请求了就有了req.body了
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

app.use(cookieParser())
app.use(session({
    secret:'keyboard cat',
    resave:false,
    saveUninitialized:true,
}))



app.set('view engine', 'ejs');
app.use(express.static('./public'))

app.get('/', function (req, res, next) {

     console.log(req.session.login)

    if(req.session.login=='1'){
        res.send('你已经成功登录'+req.session.username)
    }else{
        res.send('你没有登录')
    }

})
app.get('/gl', function (req, res, next) {

    req.session.login="1";         //设置session
    req.session.username='考拉'; 

    res.send('你已经成功登录')

})

app.listen(3000)